/**
 * @author denis.onishchenko@gmail.com
 */

package com.prapp.mediag;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;

public final class SplashScreenActivity extends Activity {

    private Handler handler = new Handler();

    private Runnable startupJob = new Runnable() {
        public void run() {
            PRApplication application = (PRApplication) getApplication();

            try {
                application.initialize();
            }
            catch (Throwable x) {
                Log.e(getClass().getName() + ".startupJob", "Can't start application", x);
                System.exit(1);
            }

            handler.post(new Runnable() {
                public void run() {
                    startActivity(new Intent(SplashScreenActivity.this, MainActivity.class));
                    finish();
                }
            });
        }
    };

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_screen);

        new Thread(startupJob).start();
    }

    protected void onPause() {
        super.onPause();

        handler.removeCallbacks(startupJob);
    }
}
